{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Range Addition II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: maxCount"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #范围求和 II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个 <code>m x&nbsp;n</code> 的矩阵&nbsp;<code>M</code><strong>&nbsp;</strong>，初始化时所有的 <code>0</code> 和一个操作数组 <code>op</code> ，其中 <code>ops[i] = [ai, bi]</code> 意味着当所有的 <code>0 &lt;= x &lt; ai</code> 和 <code>0 &lt;= y &lt; bi</code> 时， <code>M[x][y]</code> 应该加 1。</p>\n",
    "\n",
    "<p>在&nbsp;<em>执行完所有操作后</em>&nbsp;，计算并返回&nbsp;<em>矩阵中最大整数的个数</em>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1:</strong></p>\n",
    "\n",
    "<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/02/ex1.jpg\" style=\"height: 176px; width: 750px;\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> m = 3, n = 3，ops = [[2,2],[3,3]]\n",
    "<strong>输出:</strong> 4\n",
    "<strong>解释:</strong> M 中最大的整数是 2, 而且 M 中有4个值为2的元素。因此返回 4。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]\n",
    "<strong>输出:</strong> 4\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3:</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> m = 3, n = 3, ops = []\n",
    "<strong>输出:</strong> 9\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示:</strong></p>\n",
    "\n",
    "<p><meta charset=\"UTF-8\" /></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= m, n &lt;= 4 * 10<sup>4</sup></code></li>\n",
    "\t<li><code>0 &lt;= ops.length &lt;= 10<sup>4</sup></code></li>\n",
    "\t<li><code>ops[i].length == 2</code></li>\n",
    "\t<li><code>1 &lt;= a<sub>i</sub>&nbsp;&lt;= m</code></li>\n",
    "\t<li><code>1 &lt;= b<sub>i</sub>&nbsp;&lt;= n</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [range-addition-ii](https://leetcode.cn/problems/range-addition-ii/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [range-addition-ii](https://leetcode.cn/problems/range-addition-ii/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['3\\n3\\n[[2,2],[3,3]]', '3\\n3\\n[[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]', '3\\n3\\n[]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maximumPopulation(self, logs: List[List[int]]) -> int:\n",
    "        events = []\n",
    "        for s, e in logs:\n",
    "            events.append([s, 1])\n",
    "            events.append([e, -1])\n",
    "        events.sort()\n",
    "\n",
    "        res, count, maxCount = 0, 0, 0\n",
    "        for year, sign in events:\n",
    "            if sign == 1:\n",
    "                count += 1\n",
    "                if count > maxCount:\n",
    "                    res = year\n",
    "                    maxCount = count  \n",
    "            else:\n",
    "                count -= 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        row, col = m, n\n",
    "        for p, q in ops:\n",
    "            row = min(row, p)\n",
    "            col = min(col, q)\n",
    "        return row * col"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        # 最终位置(0, 0)的值等于操作的次数，找出矩阵中满足要求的次数等于操作次数的位置\n",
    "        mina, minb = m, n\n",
    "        for a,b in ops:\n",
    "            mina = min(mina, a)\n",
    "            minb = min(minb, b)\n",
    "        return mina * minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        \n",
    "        min_i = float(\"inf\")\n",
    "        min_j = float(\"inf\")\n",
    "        for i, j in ops:\n",
    "            if i < min_i:\n",
    "                min_i = i\n",
    "            if j < min_j:\n",
    "                min_j = j\n",
    "        return min_i*min_j\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        min_x, min_y = m, n\n",
    "        for x, y in ops:\n",
    "            min_x = min(min_x, x)\n",
    "            min_y = min(min_y, y)\n",
    "        \n",
    "        return min_x * min_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        i, j = m, n\n",
    "        for row in ops:\n",
    "            i = min(i, row[0])\n",
    "            j = min(j, row[1])\n",
    "        return i*j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if ops:\n",
    "            for i in ops:\n",
    "                ops[0][0]=min(i[0],ops[0][0])\n",
    "                ops[0][1]=min(i[1],ops[0][1])\n",
    "            return ops[0][0]*ops[0][1]\n",
    "        return m*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        \"\"\"\n",
    "        每次增加的数，都由操作数给出。\n",
    "        \"\"\"\n",
    "        mina, minb = m, n\n",
    "        for a, b in ops:\n",
    "            mina = min(mina, a)\n",
    "            minb = min(minb, b)\n",
    "        return mina * minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina = m\n",
    "        minb = n\n",
    "        for a,b in ops:\n",
    "            mina = a if a<mina else mina\n",
    "            minb = b if b<minb else minb\n",
    "        \n",
    "        return mina*minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina,minb = m,n\n",
    "        for a,b in ops:\n",
    "            mina = min(mina,a)\n",
    "            minb = min(minb,b)\n",
    "        return mina*minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        x = min(map(lambda x : x[0],ops))\n",
    "        y = min(map(lambda x : x[1],ops))\n",
    "        return x*y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        a = m\n",
    "        b = n\n",
    "        for op in ops:\n",
    "            x, y = op\n",
    "            a = min(a, x)\n",
    "            b = min(b, y)\n",
    "        return a * b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not len(ops):\n",
    "            return m * n\n",
    "        return min(x[0] for x in ops) * min(x[1] for x in ops)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina = m\n",
    "        minb = n\n",
    "        for a,b in ops:\n",
    "            mina = min(mina,a)\n",
    "            minb = min(minb,b)\n",
    "        return mina * minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina , minb = m , n \n",
    "        for a,b in ops:\n",
    "            mina = min(a,mina)\n",
    "            minb = min(b,minb)\n",
    "        return mina*minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m * n\n",
    "        min_col1 = min(row[0] for row in ops)  # 获取第一列的最小值\n",
    "        min_col2 = min(row[1] for row in ops)  # 获取第二列的最小值\n",
    "\n",
    "        return min_col1 * min_col2\n",
    "        # matrix = []\n",
    "        # for a in range(m):\n",
    "        #     matrix.append([0 for _ in range(n)])\n",
    "        # for op in ops:\n",
    "        #     for a in range(op[0]):\n",
    "        #         for b in range(op[1]):\n",
    "        #             matrix[a][b] += 1\n",
    "        # return matrix\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m * n\n",
    "        \n",
    "        min_a = min(op[0] for op in ops)\n",
    "        min_b = min(op[1] for op in ops)\n",
    "        return min_a * min_b\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        row, col = m,n\n",
    "        for r,c in ops:\n",
    "            row=min(row,r)\n",
    "            col=min(col,c)\n",
    "        return row*col"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0 or m*n == 0:\n",
    "            return m*n\n",
    "        min_i,min_j = ops[0][0],ops[0][1]\n",
    "        for i in range(len(ops)):\n",
    "            min_i, min_j = min(min_i,ops[i][0]),min(min_j,ops[i][1])\n",
    "        return min_i*min_j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m*n\n",
    "        ai_min = 100000\n",
    "        bi_min = 100000\n",
    "        for op in ops:\n",
    "            ai = op[0]\n",
    "            bi = op[1]\n",
    "            if ai < ai_min:\n",
    "                ai_min = ai\n",
    "            if bi < bi_min:\n",
    "                bi_min = bi\n",
    "        return ai_min*bi_min\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        zero, one = m, n\n",
    "        for x in ops:\n",
    "            zero = min(x[0], zero)\n",
    "            one = min(x[1], one)\n",
    "        return zero * one"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        #取决于ops最小的横竖的范围划分，需要找ops里面的最大值和最小值，面积也就是最后最大值的数量\n",
    "        mina=m\n",
    "        minb=n\n",
    "        for a,b in ops:\n",
    "            mina=min(mina,a)\n",
    "            minb=min(minb,b)\n",
    "        return mina*minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m * n\n",
    "        for i in range(len(ops)):\n",
    "            a = ops[i][0]\n",
    "            b = ops[i][1]\n",
    "            m = min(m, a)\n",
    "            n = min(n, b)\n",
    "        return m * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina, minb = m, n\n",
    "        for a, b in ops:\n",
    "            mina = min(mina, a)\n",
    "            minb = min(minb, b)\n",
    "        return mina * minb\n",
    "        # matrix = []\n",
    "        # for a in range(m):\n",
    "        #     matrix.append([0 for _ in range(n)])\n",
    "        # for op in ops:\n",
    "        #     for a in range(op[0]):\n",
    "        #         for b in range(op[1]):\n",
    "        #             matrix[a][b] += 1\n",
    "        # return matrix\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m * n\n",
    "        minrow,mincl = m,n\n",
    "        for item in ops:\n",
    "            if item[0] < minrow:\n",
    "                minrow = item[0]\n",
    "            if item[1] < mincl:\n",
    "                mincl = item[1]\n",
    "        return minrow * mincl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n \n",
    "        a = min(a[0] for a in ops)\n",
    "        b = min(a[1] for a in ops)\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m*n\n",
    "        min1 = float(\"inf\")\n",
    "        min2 = float(\"inf\")\n",
    "        for op in ops:\n",
    "            min1 = min(min1,op[0])\n",
    "            min2 = min(min2,op[1])\n",
    "        return min1*min2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina, minb = m, n\n",
    "        for a, b in ops:\n",
    "            mina = min(mina, a)\n",
    "            minb = min(minb, b)\n",
    "        return mina * minb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        h,l=m,n\n",
    "        for i,j in ops:\n",
    "            h=min(i,h)\n",
    "            l=min(j,l)\n",
    "        return h*l\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        \n",
    "        min_i = float(\"inf\")\n",
    "        min_j = float(\"inf\")\n",
    "        for i, j in ops:\n",
    "            if i < min_i:\n",
    "                min_i = i\n",
    "            if j < min_j:\n",
    "                min_j = j\n",
    "        return min_i*min_j\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if ops == []: return m*n\n",
    "        a_min, b_min = m, n\n",
    "        for op in ops:\n",
    "            if a_min >= op[0]:\n",
    "                a_min = op[0]\n",
    "            if b_min >= op[1]:\n",
    "                b_min = op[1]\n",
    "        return a_min*b_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        minx,miny=m,n\n",
    "        for a,b in ops:\n",
    "            minx,miny=min(minx,a),min(miny,b)\n",
    "        return minx*miny\n",
    "            \n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        for op in ops:\n",
    "            m = min(m, op[0])\n",
    "            n = min(n, op[1])\n",
    "        return m*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        min_a,min_b = m,n\n",
    "        for a,b in ops:\n",
    "            min_a = min(min_a,a)\n",
    "            min_b = min(min_b,b)\n",
    "\n",
    "        return min_a * min_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        x, y = n, m\n",
    "        for op in ops:\n",
    "            x = min(x, op[1])\n",
    "            y = min(y, op[0])\n",
    "        return x * y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return n*m\n",
    "        m1,m2=m,n\n",
    "        for i in ops:\n",
    "            m1=min(m1,i[0])\n",
    "            m2=min(m2,i[1])\n",
    "        return m1*m2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        a=len(ops)\n",
    "        if ops==[]:\n",
    "            return m*n\n",
    "        else:\n",
    "            min_a = ops[0][0]\n",
    "            min_b=ops[0][1]\n",
    "            for ai in range(a):\n",
    "                if ops[ai][1]<=min_b:\n",
    "                    min_b=ops[ai][1]\n",
    "                if ops[ai][0]<=min_a:\n",
    "                    min_a = ops[ai][0]\n",
    "            max_num=min_a*min_b\n",
    "            return max_num\n",
    "\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m * n\n",
    "        min_a, min_b = min([i for i, _ in ops]), min([j for _, j in ops])\n",
    "        return min_a * min_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        min_ai=m\n",
    "        min_bi=n\n",
    "        for o in ops:\n",
    "            if o[0]<min_ai:\n",
    "                min_ai=o[0]\n",
    "            if o[1]<min_bi:\n",
    "                min_bi=o[1]\n",
    "        return min_ai*min_bi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if ops == []:\n",
    "            return m*n\n",
    "        return min([ops[i][0] for i in range(len(ops))]) * min([ops[j][1] for j in range(len(ops))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        row, col = m, n\n",
    "        for r, c in ops:\n",
    "            row = min(row, r)\n",
    "            col = min(col, c)\n",
    "        return row * col"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        a = min(map(lambda x: x[0], ops))\n",
    "        b = min(map(lambda x: x[1], ops))\n",
    "        return a*b\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        for op in ops:\n",
    "            m=min(m,op[0])\n",
    "            n=min(n,op[1])\n",
    "        return n*m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        mina, minb = m, n\n",
    "        for a, b in ops:\n",
    "            mina = min(mina, a)\n",
    "            minb = min(minb, b)\n",
    "        return mina * minb\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if ops == []:\n",
    "            return m*n\n",
    "\n",
    "        # # 构造一个二维列表\n",
    "        # res = [[0]*n for _ in range(m)]\n",
    "        # # 根据ops进行+1\n",
    "        # for i,j in ops:\n",
    "        #     for x in range(i):\n",
    "        #         for y in range(j):\n",
    "        #             res[x][y] += 1\n",
    "        # # 找到最大值，统计数量\n",
    "        # fmax = 0\n",
    "        # for i in res:\n",
    "        #     fmax = max(fmax,max(i))\n",
    "        # cnt = 0\n",
    "        # for i in res:\n",
    "        #     cnt += i.count(fmax)\n",
    "        # # 返回\n",
    "        # return cnt\n",
    "\n",
    "        x = min([m]+[i for i,j in ops])\n",
    "        y = min([n]+[j for i,j in ops])\n",
    "        return x*y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        len_=len(ops)\n",
    "        if len_==0:\n",
    "            return n*m\n",
    "        return min(ops[i][0] for i in range(len_))*min(ops[i][1] for i in range(len_))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        return min(x[0] for x in ops) * min(x[1] for x in ops) if len(ops) else m * n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        row, col = m, n\n",
    "        for r, c in ops:\n",
    "            row = min(row, r)\n",
    "            col = min(col, c)\n",
    "        return row * col"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n \n",
    "        a = m\n",
    "        b = n\n",
    "        for i in range(len(ops)):\n",
    "            a = min(a, ops[i][0])\n",
    "            b = min(b, ops[i][1])\n",
    "\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:return m*n\n",
    "        else:\n",
    "            ans=[]\n",
    "            res=[]\n",
    "            for i in ops:\n",
    "                ans.append(i[0])\n",
    "                res.append(i[1])\n",
    "            return min(res)*min(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        for (i,j) in ops:\n",
    "            m = min(m,i)\n",
    "            n = min(n,j)\n",
    "        return m*n\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        for a, b in ops:\n",
    "            if a < m:\n",
    "                m = a\n",
    "            if b < n:\n",
    "                n = b\n",
    "        return m*n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        return min([m]+[x for x,y in ops])*min([n]+[y for x,y in ops])\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        minrow,mincol=m,n\n",
    "        for lst in ops:\n",
    "            if lst[0]<minrow:\n",
    "                minrow=lst[0]\n",
    "            if lst[1]<mincol:\n",
    "                mincol=lst[1]\n",
    "        return minrow*mincol\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        # if not ops:\n",
    "        #     return m * n\n",
    "        # # 初始化矩阵\n",
    "        # matrix = [[0] * n for _ in range(m)]\n",
    "        # for op in ops:\n",
    "        #     # 行和列的上界\n",
    "        #     row, col = op[0], op[1]\n",
    "        #     for i in range(row):\n",
    "        #         for y in range(col):\n",
    "        #             # 对指定区域内的元素加 1\n",
    "        #             matrix[i][y] += 1\n",
    "        # # 获取矩阵最大元素个数\n",
    "        # f_matrix = [num for row in matrix for num in row]\n",
    "        # max_count = f_matrix.count(max(f_matrix))\n",
    "        # return max_count\n",
    "\n",
    "        for row, col in ops:\n",
    "            m = min(m, row)\n",
    "            n = min(n, col)\n",
    "        return m * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        #求重叠部分的面积。阴影部分面积取决于宽度最小的和长度最小的\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        a=min(map(lambda x:x[0],ops))\n",
    "        b=min(map(lambda x:x[1],ops))\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if ops == []:\n",
    "            return m*n\n",
    "        l = ops[0][0]\n",
    "        r = ops[0][1]\n",
    "        for x in ops:\n",
    "            l = min(l,x[0])\n",
    "            r = min(r,x[1])\n",
    "        return l*r\n",
    "      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        #取决于ops最小的横竖的范围划分，需要找ops里面的最大值和最小值，面积也就是最后最大值的数量\n",
    "        if len(ops)==0:\n",
    "            return m*n\n",
    "        return min([x[0] for x in ops])*min([x[1] for x in ops])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        min1=min2=inf\n",
    "        for i in ops:\n",
    "            min1=min(min1,i[0])\n",
    "            min2=min(min2,i[1])\n",
    "        return min1*min2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m*n\n",
    "        high = width = float('inf')\n",
    "        for i in range(len(ops)):\n",
    "            if ops[i][0] < high:\n",
    "                high = ops[i][0]\n",
    "            if ops[i][1] < width:\n",
    "                width = ops[i][1]\n",
    "        return high * width"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops:\n",
    "            return m*n\n",
    "        min_row = m\n",
    "        min_col = n\n",
    "        for op in ops :\n",
    "            min_row = min(min_row,op[0])\n",
    "            min_col = min(min_col,op[1])\n",
    "        return min_col*min_row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m*n\n",
    "        min1 = float(\"inf\")\n",
    "        min2 = float(\"inf\")\n",
    "        for op in ops:\n",
    "            min1 = min(min1,op[0])\n",
    "            min2 = min(min2,op[1])\n",
    "        return min1*min2\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        # matrix = [[0]*n for _ in range(m)]\n",
    "        w = m\n",
    "        h = n\n",
    "        \n",
    "        for a,b in ops:\n",
    "            w = min(w,a)\n",
    "            h = min(h,b)\n",
    "        return w*h\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        #返回最小值的乘积 或者 全0返回m * n\n",
    "        return min([a[0] for a in ops]) * min([a[1] for a in ops]) if ops else m * n\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m*n\n",
    "        a,b = float(\"inf\"),float(\"inf\")\n",
    "        for op in ops:\n",
    "            if op[0] < a :\n",
    "                a = op[0]\n",
    "            if op[1] < b:\n",
    "                b = op[1]\n",
    "        return a*b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if not ops: return m * n\n",
    "        xm, ym = min([x[0] for x in ops]), min([x[1] for x in ops])\n",
    "        return xm * ym"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        min_x = m \n",
    "        min_y = n\n",
    "        for (ai,bi) in ops:\n",
    "            if ai < min_x:\n",
    "                min_x = ai\n",
    "            if bi < min_y:\n",
    "                min_y = bi\n",
    "        return min_x * min_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0: return m * n\n",
    "        return min([i[0] for i in ops]) * min(i[1] for i in ops)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        x_list  = [i[0] for i in ops if ops]\n",
    "        y_list = [i[1] for i in ops if ops]\n",
    "        return min(x_list)*min(y_list) if x_list else m*n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "\n",
    "        # 找到a,b的最小值\n",
    "        min_a = m\n",
    "        min_b = n\n",
    "\n",
    "        for index in range(len(ops)):\n",
    "\n",
    "            tmp_a = ops[index][0]\n",
    "            tmp_b = ops[index][1]\n",
    "\n",
    "            min_a = min(min_a,tmp_a)\n",
    "            min_b = min(min_b,tmp_b)\n",
    "        \n",
    "        return min_a*min_b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops)==0:\n",
    "            return m*n\n",
    "        ops.sort()\n",
    "        a=[]\n",
    "        b=[]\n",
    "        for x in ops:\n",
    "            a.append(x[0])\n",
    "            b.append(x[1])\n",
    "        return min(a)*min(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        l = len(ops)\n",
    "        a = [m,n]\n",
    "        for i in range(l):\n",
    "            b = ops[i]\n",
    "            a[0] = min(a[0],b[0])\n",
    "            a[1] = min(a[1],b[1])\n",
    "        return a[0]*a[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        r,c=m,n\n",
    "        for x,y in ops:\n",
    "            r=min(r,x)\n",
    "            c=min(y,c)\n",
    "        return r*c\n",
    "        row=[0]*(n+1)\n",
    "        col=[0]*(m+1)\n",
    "        for x,y in ops:\n",
    "            col[x]-=1\n",
    "            row[y]-=1\n",
    "            col[0]+=1\n",
    "            row[0]+=1\n",
    "        i,j=1,1\n",
    "        while i<m and col[i]==0:\n",
    "            i+=1\n",
    "        while j<n and row[j]==0:\n",
    "            j+=1\n",
    "        return i*j\n",
    "        \n",
    "        for j in range(1,n):\n",
    "            row[j]+=row[j-1]\n",
    "            if row[j]==row[0]: r+=1\n",
    "        \n",
    "        \n",
    "        # diff=[[0]*(n+1) for _ in range(m+1)]\n",
    "        # for x,y in ops:\n",
    "        #     diff[x][y]+=1\n",
    "        #     diff[0][0]+=1\n",
    "        #     diff[x][0]-=1\n",
    "        #     diff[y][0]-=1\n",
    "        # c=Counter()\n",
    "        # for i in range(m-1,-1,-1):\n",
    "        #     for j in range(n-1,-1,-1):\n",
    "        #         diff[i+1][j+1]+=diff[i+1][j]+diff[i][j+1]-diff[i][j]\n",
    "        #         c[diff[i+1][j+1]]+=1\n",
    "        # print(diff)\n",
    "        # mx=max(c.keys())\n",
    "        # return c[mx]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n",
    "        if len(ops) == 0:\n",
    "            return m*n\n",
    "        aa, bb = [], []\n",
    "        for a, b in ops:\n",
    "            aa.append(a)\n",
    "            bb.append(b)\n",
    "        return min(aa) * min(bb)\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
